/**
 * @file font_struct.h
 * @author ThomasKingFree (dulu150@126.com)
 * @brief 定义字库组织结构
 * @version 0.1
 * @date 2021-07-17
 *
 * @copyright Copyright (c) 2021
 *
 */

#ifndef FONT_STRUCT_H
#define FONT_STRUCT_H

#include <cstdint>

namespace YueGUI {
constexpr uint32_t FONT_MAGIC_WORD = 0xabcddcba;
struct FontHeader {
    uint32_t magicWord = FONT_MAGIC_WORD;
    uint32_t versionCode = 0;
    uint32_t totalFontNum = 0;
    uint32_t glyphIndexOffset = 0;
    uint32_t glyphIndexCacheSize = 0;
};

/* 用于快速命中单个字符 */
struct GlyphIndexCache {
    uint32_t unicode = 0;
    uint32_t offset = 0;
};

struct BitmapInfo;
struct GlyphMetaData;
/* 存放在字库中单个字符完整信息 */
struct GlyphInfo {
    GlyphMetaData metaData = {0};
    BitmapInfo bitmap = {0};
};

/* 单个字符的关键信息,用于文本显示的时候快速计算位置 */
struct GlyphMetaData {
    int16_t width = 0;
    int16_t height = 0;
};

/* 字符bitmap信息,用于字符绘制 */
struct BitmapInfo {
    uint8_t bitmapPosX = 0; // freetype 生成的bitmap相对于字形位置的X轴偏移量
    uint8_t bitmapPosY = 0; // freetype 生成的bitmap相对于字形位置的Y轴偏移量
    uint8_t bitmapWidth = 0;
    uint8_t bitmapHeight = 0;
    uint8_t *bitmapData = nullptr;
};
} // namespace YueGUI
#endif
